package com.ebc.eservice.controller.app;

import com.ebc.eservice.service.app.AppLoginService;
import com.ebc.eservice.service.impl.login.LoginService;
import com.ebc.eservice.util.CurrentUser;
import com.ebc.eservice.util.JsonResult;
import com.ebc.eservice.util.common.constant.ApiTextHelperConstant;
import com.ebc.eservice.util.common.constant.DeveloperConstant;
import com.ebc.eservice.vo.user.LoginUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: Joey
 * @Description:小程序端登录
 * @date:2022/9/23 15:48
 */
@Api(tags = "小程序端-登录")
@RestController
@RequestMapping("/app")
@Slf4j
public class LoginAppController {

    @Autowired
    private AppLoginService loginService;

    @ApiOperation(value = "app-登录", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH +" [登录账号只限于用户与员工]")
    @PostMapping("/login") //RequestBody
    public JsonResult LoginToken(LoginUserVo loginUserVo){
        log.info("app登录信息:{}", loginUserVo);
        return loginService.appLogin(loginUserVo);
    }

    @ApiOperation(value = "app-注销", notes = ApiTextHelperConstant.DEVELOPER + DeveloperConstant.FH)
    @PostMapping("/user/logout")
    public JsonResult appLogout(Integer cardId){ //Integer cardId
        CurrentUser user = new CurrentUser();
        int currentId = user.getCurrentUser();
        System.out.println("=======小程序端账户 退出:"+currentId);
        System.out.println("=======当前名片 退出:"+cardId);
        return loginService.logout(cardId);//Integer cardId
    }

}
